package phapp.service.system.impl;

import java.util.*;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;
import javacommon.base.*;
import phapp.model.system.*;
import phapp.dao.system.*;
import phapp.service.system.impl.*;
import phapp.service.system.*;

/**
 * Title: t_keyword_data 业务处理层 Description: spring事务实现层,调用Dao层取数据 Copyright:
 * Copyright (c) 2012-10 Company:
 * 
 * @author you name
 * @version 1.0
 */

@Component("keywordManager")
@Transactional
public class KeywordManagerImpl extends BaseManager<Keyword, java.lang.Integer> implements KeywordManager
{

   /** 定义Dao */
   private KeywordDao keywordDao;

   /** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性 */
   public void setKeywordDao(KeywordDao dao)
   {
      this.keywordDao = dao;
   }

   /** 获取Dao */
   public EntityDao getEntityDao()
   {
      return this.keywordDao;
   }

   /**
    * <p>
    * 分页查询Keyword<br>
    * 
    * @param PageRequest
    *           pr
    * @return Page
    * @author
    */
   @Transactional(readOnly = true)
   public Page findByPageRequest(PageRequest pr)
   {
      return keywordDao.findByPageRequest(pr);
   }

   /**
    * <p>
    * 批量删除 Keyword<br>
    * 
    * @param Keyword
    *           u
    * @return Boolean
    * @author
    */
   public Boolean removeByIdArry(Keyword u)
   {
      Boolean result = false;
      int i = -1, size = u.getIdList().size();
      i = keywordDao.removeByIdArry(u);
      if (i == size)
      {
         result = true;
      }
      else
      {
         throw new RuntimeException();
      }
      return result;
   }
   
   public Boolean containKeyword(String strWord)
   {
      int i = 0;
      String strKey = "";
      Boolean bStatus = false;
      Keyword keywordData = null;
      ArrayList<Keyword> listWord = null;
      
      listWord = (ArrayList<Keyword>) keywordDao.findAll();
      for(i=0; i<listWord.size(); i++)
      {
         keywordData = listWord.get(i);
         strKey = keywordData.getKeyWord();
         
         if(strWord.contains(strKey) == true)
         {
            bStatus = true;
            break;
         }
      }
      
      return bStatus;
   }

}
